package com.work.service;
/**
 * @author： li
 * @date： 2021-05-28 18:45
 * @version 1.0
 */

import com.work.dao.emaildao;
import com.work.pojo.email;
import com.work.pojo.user;
import com.work.util.PageUtil;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author： Administrator
 * @date： 2021-05-28 18:45
 * @version 1.0
 */
public class mailservice {

    /**
     * 获取最大页数
     * @param pageSize
     * @return
     */
    public static Integer maxPage(String cookies,Integer pageSize){
        Integer page = 0;
        try {
            email em=new email();
            em.setCookies(cookies);
            Integer count = emaildao.countNum(em);
            page = (int)Math.ceil((double)count/pageSize);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return page;
    }
    /**
     * 通过工具类使用集合进行分页
     * @param pageSize
     * @param pageNum
     * @return
     */
    public static List<email> page(String cookies,Integer pageSize,Integer pageNum) {
        List<email> page=null;
        email em=new email();
        em.setCookies(cookies);
        //System.out.println("mailservice的cookies："+cookies);
        try{
        page = PageUtil.page(emaildao.selectbycookies(em),pageSize,pageNum);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return page;
    }
}
